package com.atguigu.gmall.product.controller;

import com.atguigu.gmall.common.result.Result;
import com.atguigu.gmall.model.product.BaseTrademark;
import com.atguigu.gmall.product.service.BaseTrademarkService;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: gmall-parent
 * @author: Mr.Zhuo
 * @create: 2022-04-03 14:37
 **/
@RestController
@RequestMapping("/admin/product/baseTrademark")
public class BaseTrademarkController {

    @Autowired
    private BaseTrademarkService baseTrademarkService;

    ///admin/product/baseTrademark/{page}/{limit}
    @ApiOperation("品牌管理分页列表")
    @GetMapping("{page}/{limit}")
    public Result baseTrademark(@PathVariable Long page,
                                @PathVariable Long limit) {

        // 分页条件，调用servic方法
        Page<BaseTrademark> trademarkPage = new Page<>(page, limit);
        IPage<BaseTrademark> iPage = this.baseTrademarkService.baseTrademark(trademarkPage);
        // 返回数据
        return Result.ok(iPage);
    }

    //    /admin/product/baseTrademark/save
    @ApiOperation("品牌管理保存")
    @PostMapping("save")
    public Result save(@RequestBody BaseTrademark baseTrademark) {
        // 调用service方法
        this.baseTrademarkService.mySave(baseTrademark);

        // 返回结果
        return Result.ok();
    }


    @ApiOperation(value = "获取BaseTrademark")
    @GetMapping("get/{id}")
    public Result get(@PathVariable String id) {
        // 调用service方法
        BaseTrademark baseTrademark = baseTrademarkService.getById(id);
        // 返回结果
        return Result.ok(baseTrademark);
    }

    @ApiOperation(value = "修改BaseTrademark")
    @PutMapping("update")
    public Result updateById(@RequestBody BaseTrademark banner) {
        baseTrademarkService.updateById(banner);
        return Result.ok();
    }

    @ApiOperation(value = "删除BaseTrademark")
    @DeleteMapping("remove/{id}")
    public Result remove(@PathVariable Long id) {
        baseTrademarkService.removeById(id);
        return Result.ok();
    }


}
